#ifndef __AI_SERVICE_TASK_H__
#define __AI_SERVICE_TASK_H__

#include <queue>
#include <mutex>
#include <functional>
#include <condition_variable>
#include <cstddef>
#include <thread>
#include <cstdio>
#include <string>
#include <map>
#include <memory>

#include "utils.h"
#include "params.h"

namespace ai_service {

class AsyncTaskBase
{
public:
    virtual ~AsyncTaskBase() {}

    virtual Ret CommitTo(AsyncTaskQueue& queue,
        AsyncTaskParams& params);
    virtual Ret Sync();
    virtual Ret Notify();

    virtual Ret Init(const Config& config);
    virtual Ret Destroy();

    virtual Ret ExecuteTask(AsyncTaskParams& params);

    Ret Execute(AsyncTaskParams& params);
    
    void PreCheck(AsyncTaskParams& params);
    
    void PostUpdate(AsyncTaskParams& params);

    void ElapseFromCommit2Exec() {
        m_perf.tick(m_name + " Commit2Exec");
    }

    const std::string GetTaskName() const { return m_name; }

protected:
    std::mutex m_mutex;
    std::condition_variable m_cond;
    std::string m_name = "AsyncTaskBase";
    Perf m_perf;
};
}

#endif // __AI_SERVICE_TASK_H__